<template>
	<view class="Global">
		<!-- 背景图片铺满 -->
		<!-- <image class="imagepage" src="/static/background@2x.png" mode=""></image> -->
		<bgImage></bgImage>
		<!-- <view class="personnel" :style="{'height':tarbarHeight+'px'}">
			<image @click="backOnClick" src="../../../static/logo.png" class="backImg" mode=""></image>
			<text class="title">{{personnelInfo}}</text>
		</view> -->
		<MyNav :title="title" bgColor="" :backIcon="isback"></MyNav>

		<view class="updateContent">

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">工序模版</text>
					<text class="title2">*</text>
				</view>

				<!-- 	<input @input="onInputAccount" class="title3" type="text" :value="updateManagerData.templateId"  placeholder-class="title3"
					placeholder="请输入" /> -->

				<picker mode="selector" :value="hobbyValue" :range="hobbyList" range-key="templateName"
					@change="chooseHobby">
					<!-- <input @input="onInputAccount" class="title3" type="text" value="" placeholder-class="title3"
							placeholder="请输入" /> -->
					<view class="searchPickerContentBg">
						<text class="searchPickerText">{{hobbyValue}}</text>

						<uni-icons type="down" size="14"></uni-icons>

					</view>
				</picker>
			</view>

			<view class="line"></view>

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">编号</text>
					<text class="title2">*</text>
				</view>

				<input @input="onInputPass" class="title3" type="text" :value="updateManagerData.processCode"
					placeholder-class="title3" placeholder="请输入" />
			</view>

			<view class="line"></view>

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">工序名称</text>
					<text class="title2">*</text>
				</view>

				<input @input="onInputPassName" class="title3" type="text" :value="updateManagerData.processName"
					placeholder-class="title3" placeholder="请输入" />
			</view>

			<view class="line"></view>

			<view class="updateName">
				<view class="updateNameTitle">
					<text class="title1">工序工价</text>
					<text class="title2">*</text>
				</view>


				<input @input="onInputPassPrice" class="title3" type="text" :value="updateManagerData.wages"
					placeholder-class="title3" placeholder="请输入" />
			</view>



		</view>


		<view class="loginContent">

			<button @click="addClick()" style="color:#ffffff" class="login" type="default">{{login}}</button>
		</view>


	</view>
</template>

<script>
	import MyNav from '@/components/customnavbar.vue'

	import bgImage from '@/components/backgroundImage.vue'
	import {

		updateProcessManager,
		getProcessTemplateManager
	} from '@/pages/api/api.js'
	export default {
		components: {
			MyNav,
			bgImage
		},
		data() {
			return {
				title: '修改',
				isback: true,

				personnelInfo: '修改',
				tops: 0,
				height: 0,
				tarbarHeight: 0,
				login: '确认',

				// 修改数据对象
				updateManagerData: {},


				//
				hobbyList: [],
				hobbyValue: '请选择模板',




				sizeManagerData: {
					storeId: '',
					tenantId: '',
					pageNum: '1', // 当前页
					pageSize: '100', //页码大小
				},
			}
		},

		onLoad: function(option) {

			/* let item = JSON.parse(decodeURIComponent(option.query.item));
			        console.log('传递数据',item);  // 打印出传递的复杂参数 */

			let item = JSON.parse(decodeURIComponent(option.item));
			this.updateManagerData = item
			this.updateManagerData.wages = item.wages + ''
			console.log('数据传递了', item, this.updateManagerData); // 打印出传递的复杂参数

			this.hobbyValue = this.updateManagerData.templateId

			this.loadData()
		},
		methods: {

			// 模板选择
			chooseHobby(e) {
				// console.log(e);
				let key = e.detail.value
				this.hobbyValue = this.hobbyList[key].templateName
				console.log("模板", this.hobbyValue, e)
				this.updateManagerData.templateId = this.hobbyList[key].id
			},

			// 获取编号输入框的值
			onInputAccount(e) {
				this.updateManagerData.templateId = e.detail.value
			},
			// 获取尺寸名称框输入的值
			onInputPass(e) {

				this.updateManagerData.processCode = e.detail.value
			},
			// 获取编号输入框的值
			onInputPassName(e) {
				this.updateManagerData.processName = e.detail.value
			},
			// 获取尺寸名称框输入的值
			onInputPassPrice(e) {
				this.updateManagerData.wages = e.detail.value
			},


			backOnClick() {
				uni.navigateBack({
					delta: 1
				});
				console.log('点击返回');
			},

			addClick() {


				if (!this.updateManagerData.templateId || !this.updateManagerData.processCode || !this.updateManagerData
					.processName || !this.updateManagerData.wages) {
					uni.showToast({
						title: '内容不能为空'
					});
					return;
				}

				// 新增
				updateProcessManager(this.updateManagerData).then((res) => {
					// console.log('新增数据', res);

					if (res.code == 200) {
						// 表示添加成功 则返回上一页
						// 表示添加成功 则返回上一页
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2]; //上一个页面
						//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
						prevPage.setData({
							isRefresh: 1
						})
						this.backOnClick()

					}
					// 显示提示信息
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});

				}).catch((err) => {
					// console.log('新增失败', err);
				});



			},

			// 模板数据
			loadData() {

				const app = getApp();
				this.sizeManagerData.storeId = app.globalData.storeId
				this.sizeManagerData.tenantId = app.globalData.tenantId
				// 重置
				this.sizeManagerData.pageNum = 1;

				getProcessTemplateManager(this.sizeManagerData).then((res) => {
					// console.log('11获取数据成功', res);


					if (res.code == 200) {
						this.totalPage = (res.total / this.sizeManagerData.pageSize)
						if (this.totalPage > 1) {
							++this.totalPage
						}

						// 计算总页数
						this.totalPage = parseInt(this.totalPage)

						// this.listSizeData = this.listSizeData.concat(res.rows)
						this.hobbyList = [...this.hobbyList, ...res.rows]




					}
					// console.log('2211获取数据成功', res, this.totalPage, this.listSizeData.length);
				}).catch((err) => {
					// console.error('11获取数据失败', err);
				});
			},





		},
		onReady() {
			// 获取标题栏和状态栏高度
			uni.getSystemInfo({
				success: (e) => {
					this.tops = e.statusBarHeight;
					let custom = uni.getMenuButtonBoundingClientRect();
					this.height = custom.height + (custom.top - e.statusBarHeight) * 2;
					this.tarbarHeight = this.tops + this.height;
				}
			})

		}
	}
</script>

<style>
	.searchPickerText {

		margin-left: 20rpx;
		font-family: HarmonyOS Sans SC;
		font-weight: 600;
		font-size: 24rpx;
		color: #333333;

		display: flex;
		justify-content: center;
		align-items: center;

		margin-right: 10rpx;

	}

	.searchPickerImg {
		width: 20rpx;
		height: 10rpx;
		margin-right: 20rpx;

	}

	.searchPickerContentBg {
		width: 180rpx;
		height: 60rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin-right: 15rpx;
		margin-left: 15rpx;
		display: flex;
		align-items: center;



	}

	.loginContent {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 750rpx;


	}

	.login {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		width: 550rpx;
		height: 110rpx;

		border-radius: 30rpx;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
		text-align: center;
		font-weight: bold;

		margin-top: 60rpx;
		background: linear-gradient(90deg, #45A8FF, #0AE1C6);

	}

	.line {
		width: 100%;
		height: 1rpx;
		background: #F9FCFF;



	}

	.title1 {
		font-size: 24rpx;
		color: #333333;

	}

	.title3 {
		font-size: 24rpx;
		color: #333333;
		margin-right: 30rpx;
		width: 100rpx;

	}

	.title2 {
		font-size: 24rpx;
		color: red;

	}

	.updateNameTitle {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 30rpx;
	}

	.updateName {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

		width: 100%;
		height: 50%;
	}


	.updateContent {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 690rpx;
		height: 320rpx;
		background: #FFFFFF;
		border-radius: 30rpx 30rpx 30rpx 30rpx;
		margin-top: 40rpx;
		margin-left: 30rpx;
	}




	.imagepage {

		background-size: cover;
		background-repeat: no-repeat;
		background-position: center center;
		position: absolute;
		z-index: -1;
		left: 0;
		right: 0;
		bottom: 0;
		right: 0;
		width: 100%;
		height: 100%;
	}
</style>